package com.example.padlock.data.impl;

import java.net.ConnectException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;

import com.example.padlock.data._interface.IHttpPostImpl;
import com.example.padlock.data.bean.JsonKeys;
import com.example.padlock.data.bean.UrlBean;
import com.example.padlock.data.common.beanutil.StringUtil;
import com.example.padlock.data.common.httputil.HttpUtil;
import com.example.padlock.data.common.httputil.JsonUtil;
import com.example.padlock.data.entity.AdResultEntity;

public class GetAdImpl extends IHttpPostImpl<AdResultEntity>{
	
	@Override
	public AdResultEntity getSingleByPost(String... params)
			throws ConnectException, JSONException {
		AdResultEntity entity=null;
		List<NameValuePair> pairs=new ArrayList<NameValuePair>();
		pairs.add(new BasicNameValuePair(JsonKeys.PAD_CODE, params[0]));
		String result=HttpUtil.getResultByPOST(UrlBean.GET_AD, pairs);
		if (StringUtil.isEmpty(result))
			return null;
		try {
			entity = new JsonUtil<AdResultEntity>().encodeJson(result,
					AdResultEntity.class);
		} catch (IllegalStateException e) {
			
		}
		return entity;
	}

}
